package test

import (
	"fmt"
	"github.com/jinzhu/gorm"
	"managementsystem/conn"

	"managementsystem/structs"
)

//查询一个学生的所有成绩

//查询单个学生的所有成绩(无视图)
func SelectOneScore(db *gorm.DB){

	var Result structs.S

	err1 := db.Table("s").Where("sno='200102'").Find(&Result).Error
	if err1 != nil {
		panic(err1)
	}
	fmt.Printf("%#v%#v\n",Result.Sno,Result.Sname)

	var Results []structs.SelectStudentScore
	err2 := db.Table("sc").Select("sc.score as score, c.cname as cname").Joins("left join c on sc.cno = c.cno where sc.sno='200102'").Scan(&Results).Error
	if err2 != nil {
		panic(err2)
	}

	for _,v :=range Results{
		fmt.Println(v.Cname,v.Score)
	}
}


//查询单个学生的所有成绩(视图)
func SelectOneScoreView(db *gorm.DB) {
	var Result structs.S

	err1 := db.Table("infosearch").Where("sno='200102'").Find(&Result).Error
	conn.ErrCheck(err1)
	fmt.Printf("%#v%#v\n",Result.Sno,Result.Sname)

	var Results []structs.SelectStudentScore
	err2 := db.Table("scoresearch").Where("sno='200102'").Scan(&Results).Error
	conn.ErrCheck(err2)

	for _,v :=range Results{
		fmt.Println(v.Cname,v.Score)
	}

}
